//
//  OrderOperationView.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/27.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "OrderOperationView.h"

@interface OrderOperationView ()
@property(nonatomic,strong)UIView *shadeView;

@end

@implementation OrderOperationView

-(instancetype)initWithPopOrderOperation:(NSArray *)butNum theTitleStr:(NSString *)titStr theTosStr:(NSString *)tosStr{
    if (self = [super initWithFrame:CGRectZero]) {
        self.layer.cornerRadius = 10.0;
        self.layer.masksToBounds = YES;
        _shadeView = [[UIView alloc]initWithFrame:kScreen_Bounds];
        _shadeView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.6];
        _shadeView.tag = 1000;
        self.backgroundColor = [UIColor whiteColor];
        [self.shadeView addSubview:self];
        CGFloat selfHeight = kHeightProportion_In_iPhoneTriploid(185);
        if (tosStr.length == 0) {
            selfHeight = kHeightProportion_In_iPhoneTriploid(120);
        }
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.shadeView);
            make.centerY.equalTo(self.shadeView).offset(-kHeightProportion_In_iPhoneTriploid(30));
            make.width.equalTo(@(KScreenWidth - kWidthProportion_In_iPhoneTriploid(100)));
        }];
        //
        GLGWLabel * titleLabel = [[GLGWLabel alloc] initWithFont:BOLDSYSTEMFONT(16) theColor:kColor_Rule_Black inSuperView:self];
        titleLabel.text = titStr;
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_top).offset(kHeightProportion_In_iPhoneTriploid(20));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(22)));
            make.centerX.equalTo(self);
        }];
        //
         GLGWLabel * messagelabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(14) theColor:kColor_Rule_Black inSuperView:self];
        messagelabel.attributedText =[GLGWLabel changeLineWithSpace:8 theInoutText:tosStr];
        messagelabel.numberOfLines = 0;
        messagelabel.textAlignment = NSTextAlignmentCenter;
        [messagelabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(titleLabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(19));
        }];
        if (titStr.length == 0) {
            [messagelabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(self);
                make.top.equalTo(self.mas_top).offset(kHeightProportion_In_iPhoneTriploid(24));
            }];
        }
        CGFloat butWidth = (KScreenWidth - kWidthProportion_In_iPhoneTriploid(100))/(butNum.count);
        for (int i=0; i<butNum.count; i++) {
            GLGWButton * but = [[GLGWButton alloc] initWithTitle:butNum[i] titleLableFont:BOLDSYSTEMFONT(16) titleLableColor:[UIColor colorWithHexString:@"#A89A60"] theCornerRadius:0 theBorderWidth:0.6 theBorderColor:[UIColor colorWithHexString:@"#EAEAEA"] backgroundColr:[UIColor whiteColor] inSuperView:self];
            [but mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(messagelabel.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(20));
                make.left.equalTo(self.mas_left).equalTo(@(butWidth*i));
                make.bottom.equalTo(self.mas_bottom).offset(0);
                make.width.equalTo(@(butWidth));
                make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(50)));
            }];
            if (butNum.count > 1 && i==0) {
                [but setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal];
            }
            but.tag = 310+i;
            [but addTarget:self action:@selector(butAction:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    return self;
}

-(void)butAction:(GLGWButton *)sender{
    if (self.Block_CaseAction) {
        self.Block_CaseAction(sender.tag);
    }
    [self dissmiss];
}

//显示
- (void)show {
    self.transform = CGAffineTransformMakeScale(0.8f, 0.8f);
    [UIView animateWithDuration:0.2 animations:^{
        [self dissmiss];
        self.transform = CGAffineTransformIdentity;
        [[UIApplication sharedApplication].keyWindow addSubview:self.shadeView];
    } completion:^(BOOL finished) {
    }];
}

- (void)dissmiss {
    NSEnumerator *subviewsEnum = [[UIApplication sharedApplication].keyWindow.subviews reverseObjectEnumerator];
    for (UIView *subview in subviewsEnum) {
        if (subview.tag == 1000) {
            [subview removeFromSuperview];
        }
    }
}

@end
